// game resources

// http://kyogremaster.deviantart.com/art/All-Pokemon-Trainer-Sprites-137787432

var g_resources = 
[
{name: "ForestSet",	type: "image",	src: "data/sprite/ForestSet.png"},
{name: "link",	type: "image",	src: "data/sprite/link.png"},
{name: "ash",	type: "image",	src: "data/sprite/ash.png"},
{name: "32x32_font",type: "image",  src: "data/sprite/32x32_font.png"},
{name: "link_title",type: "image",src: "data/sprite/link_title.png"},
{name: "area01",	type: "tmx",	src: "data/area01.tmx"},
];

var jsApp	= 
{	
	// Initialize the jsApp

    loadLevel: function() {
         var ev = me.game.currentLevel.getLayerByName("Eventos");
         if(ev==null || ev==undefined) return;
         alert("TEM"); // NAO SAI ESSA PORRA DE MSG !!!!
    },

	onload: function()
	{
		
		// video
		if (!me.video.init('jsapp', 640, 480, false, 1.0))
		{
			alert("Sorry but your browser does not support html 5 canvas.");
			return;
		}

        me.game.onLevelLoaded = this.loadLevel.bind(this);
		// "audio"
		//me.audio.init("mp3");
		
		// i love the music & SFX, but when
		// developing it can quickly become boring !
		//me.audio.disable();
		
		// set all resources to be loaded
		me.loader.onload = this.loaded.bind(this);
		
		// set all resources to be loaded
		me.loader.preload(g_resources);

		// load everything & display a loading screen
		me.state.change(me.state.LOADING);
	},
	// Callback when everything is loaded
	
	loaded: function ()
	{
		// set the "Play/Ingame" Screen Object
		me.state.set(me.state.MENU, new TitleScreen());

		// set the "Play/Ingame" Screen Object
		me.state.set(me.state.PLAY, new PlayScreen());

		// set a global fading transition for the screen
		me.state.transition("fade", "#FFFFFF", 15);

		// add our player entity in the entity pool
		me.entityPool.add("mainPlayer", PlayerEntity);
        me.entityPool.add("Evento", Event);

        // enable the keyboard
        me.input.bindKey(me.input.KEY.LEFT,     "left");
        me.input.bindKey(me.input.KEY.X,     "debug", true);
        me.input.bindKey(me.input.KEY.RIGHT,    "right");
        me.input.bindKey(me.input.KEY.UP,     "up");
        me.input.bindKey(me.input.KEY.DOWN,    "down");
        // bind X key, and disable key repeating (2nd parameter)
       // me.input.bindKey(me.input.KEY.X,        "strike", true);
        
		// enable dirty rectangle
		//me.sys.dirtyRegion = true;
        //me.debug.renderDirty = true;
		// collision box debug
		//me.debug.renderHitBox = true;
                
        // start the game 
        me.state.change(me.state.MENU);
	}

}; // jsApp


//bootstrap :)
window.onReady(function() 
{
	jsApp.onload();
});
